package tests.suite.tests
{
	import com.gdcnano.nanoamp.media.sound.ID3InfoWrapper;
	
	import flash.media.ID3Info;
	import flash.utils.ByteArray;
	
	import flexunit.framework.Assert;
	
	public class ID3InfoWrapperTest
	{
		private static const WIN_ALBUM:String = "Весёлые картинки";
		
		private static const WIN_ARTIST:String = "Ляпис трубецкой";
		
		private static const WIN_SONGNAME:String = "Я буду";
				
		private static const U_ALBUM:String = "Сигнал из космоса";
		
		private static const U_ARTIST:String = "Сплин";
		
		private static const U_SONGNAME:String = "Зеленая песня";
		
		private var _id3Info:ID3InfoWrapper;
		
		private var _id3InfoWin1251:ID3Info;
		
		private var _id3InfoWin1251WithoutArtist:ID3Info;
		
		private var _id3InfoUnicode:ID3Info;
		
		public function ID3InfoWrapperTest()
		{
			_id3InfoWin1251 = getID3Info(toWindows1251(WIN_ALBUM), toWindows1251(WIN_ARTIST), toWindows1251(WIN_SONGNAME));
			
			_id3InfoWin1251WithoutArtist = getID3Info(toWindows1251(WIN_ALBUM), "", toWindows1251(WIN_SONGNAME));
			
			_id3InfoUnicode = getID3Info(U_ALBUM, U_ARTIST, U_SONGNAME);
		}
		
		[Test]
		public function canConvertWindows1251ID3Info():void
		{
			_id3Info = new ID3InfoWrapper(_id3InfoWin1251);
			
			Assert.assertEquals(WIN_ALBUM, _id3Info.album);
			
			Assert.assertEquals(WIN_ARTIST, _id3Info.artist);
			
			Assert.assertEquals(WIN_SONGNAME, _id3Info.songName);
		}
		
		[Test]
		public function canDefineEncodingByAlbum():void
		{
			_id3Info = new ID3InfoWrapper(_id3InfoWin1251WithoutArtist);
			
			Assert.assertEquals(WIN_ALBUM, _id3Info.album);
			
			Assert.assertEquals("", _id3Info.artist);
			
			Assert.assertEquals(WIN_SONGNAME, _id3Info.songName);
		}
		
		[Test]
		public function canWrapUnicodeID3Info():void
		{
			_id3Info = new ID3InfoWrapper(_id3InfoUnicode);
			
			Assert.assertEquals(U_ALBUM, _id3Info.album);
			
			Assert.assertEquals(U_ARTIST, _id3Info.artist);
			
			Assert.assertEquals(U_SONGNAME, _id3Info.songName);
		}
		
		private function getID3Info(album:String, artist:String, songName:String):ID3Info
		{
			var info:ID3Info = new ID3Info();
			
			info.album = album;
			info.artist = artist;
			info.songName = songName;
			
			return info;
		}
		
		private function toWindows1251(data:String):String
		{
			var b:ByteArray = new ByteArray();
			b.writeMultiByte(data,"windows-1251");
			return b.toString();
		}
	}
}